<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="true" @tap="back">
			<block slot="content">发布圈子</block>
		</cu-custom>
		<view class="all">
			<view class="area" style="height: 200rpx;">
				<!-- <textarea class="textarea" placeholder="说点什么......" v-model="content"></textarea> -->
				<textarea maxlength="255" class="textarea" placeholder="说点什么......" v-model="content"></textarea>
			</view>
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
						:data-url="imgList[index]">
						<image :src="imgList[index]" mode="aspectFill" v-model="image"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
							<text class='iconfont icon-guanbi'></text>
						</view>
					</view>

					<!-- <view class="solids" v-if="imgList.length<4">
						<text class='cuIcon-cameraadd'></text>
					</view> -->
					<wzh-upload :count="10" @onUpload="imageUpload" class="up-img" v-if="imgList.length<9">
						<view class="cuIcon-cameraadd"></view>
					</wzh-upload>
				</view>
			</view>
			
		</view>
		<view class="address">
			<view class=" place iconfont icon-dizhi"></view>
			<view class="place_li">我的位置</view>
			<view class=" right iconfont icon-you1" @tap="showMap"></view>
		</view>
		<view class="fabu"><button class="btn" @tap="Publish">发布</button></view>

	</view>
</template>
<script>
	const {
		appLogin,
		httpGet,
		httpPost,
		msg
	} = require("@/utils/common.js")
	export default {
		data() {
			return {
				imgList: [],
				type: 1,
				image: ',',
				content: '',
				lat:'',
				lng:''
			}
		},
		onLoad() {
			appLogin((user_info) => {
				console.log(user_info)
				this.showMap()

				// this.Publish()
			})
		},
		methods: {
			DelImg(e) {
				uni.showModal({
					title: '',
					content: '确定要删除吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			showMap() {
				/* uni.getLocation({
					type: 'gcj02', //返回可以用于uni.openLocation的经纬度
					success: function(res) {
						const latitude = res.latitude;
						const longitude = res.longitude;
						uni.openLocation({
							latitude: latitude,
							longitude: longitude,
							success: function() {
								console.log('success');
							}
						});
					}
				}); */
				uni.getLocation({
				    type: 'wgs84',
				    success: (res)=>{
				        console.log('当前位置的经度：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						this.lat = res.latitude;
						this.lng = res.longitude
				    }
				});
			},
			
			Publish() {
				console.log('点击了按钮')
				if(!this.content){
					uni.showToast({
						icon:'none',
						title:'请输入内容',
						duration: 2000
					});
					return;
				}
				
				httpPost({
					url: '/api/circle/add',
					data: {
						type: this.type,
						image: this.imgList.join(','),
						content: this.content,
						lat:this.lat,
						lng:this.lng
					}
				}).then((res) => {
					console.log(res)
					uni.reLaunch({
						url: 'practicecircled'
					})
				})
			},
			imageUpload(res) {
				this.imgList.push(res)
				// console.log(res)
			},
			back() {
				uni.navigateTo({
					url: 'practicecircled'
				})
			},

		},
	}

	// getstudentinfo(){
	// 	httpPost({
	// 		url:'/api/circle/add',
	// 		data:{
	// 			type:this.type,
	// 			video:this.video,
	// 			content:this.content,
	// 			image:this.imgList.join(',')
	// 		}
	// 	}).then((res)=>{
	// 		console.log(res.result)
	// 		this.type = res.result.type
	// 		this.image = res.result.image
	// 		this.video = res.result.video
	// 		this.content = res.result.content
	// 	})
	// },
</script>

<style>
	.all {
		background-color: #ffffff;
		
	}

	.textarea {
		height: 150rpx;
	}

	.area {
		padding: 20rpx;
	}

	.area>textarea {
		width:100%;
	}

	.address {
		/* width: 100vw; */
		width:100%;
		height: 90rpx;
		padding: 22rpx;
		margin-top: 20rpx;
		background-color: #FFFFFF;
	}

	.place {
		float: left;
		margin: 20rpx;
	}

	.place_li {
		margin-top: 10rpx;
		float: left;
	}

	.right {
		margin-top: 20rpx;
		float: right;
		
	}

	.btn {
		color: white;
		background-color: #3b73f6;
		border-radius: 50rpx;
	}

	.fabu {
		margin-top: 300rpx ;
		height: 200rpx;
		padding: 20rpx;
	}

	.solids {
		padding-bottom: calc((100% - 60rpx)/4);
		height: 0;
		width: calc((100% - 60rpx)/4)
	}

	.cuIcon-cameraadd {
		color: #a7a7a7;
		font-size: 70rpx;
		padding: 30rpx;
	}
	.up-img{
		flex-wrap: wrap;
		
	}
</style>

